package org.rich.charlesmurphy.ui.renderers;

import java.awt.Component;

import javax.swing.JLabel;
import javax.swing.JTable;
import javax.swing.table.TableCellRenderer;

import org.ddevil.data.Data;
import org.windowkit.toolkit.widget.table.RecordTableModel;
import org.windowkit.toolkit.widget.table.render.AbstractTableCellRendererDecorator;

/**
 * Renders URL's by bolding the final portion of the resource.
 * i.e. 'Spawn.htm' for the URL: rightHandAndPalm/isLike/theCapeon/Spawn.htm
 * @author Rich
 */
public class UrlRenderer extends AbstractTableCellRendererDecorator {

	public UrlRenderer() {
		super();
	}

	/**
	 * @param decorateMe
	 */
	public UrlRenderer(TableCellRenderer decorateMe) {
		super(decorateMe);
	}

	@Override
	protected void decorate(Component c, Data d, RecordTableModel model,
			JTable table, Object value, CellInfo cellInfo) {

		if (c instanceof JLabel) {
			JLabel lbl = (JLabel)c;

			String url = value.toString();
			String newUrl;
			int idx = url.lastIndexOf("/");
			if (idx > -1) {
				newUrl = "<html><div style='white-space: nowrap;'><span>" + url.substring(0, idx + 1) + "</span><strong>" + url.substring(idx + 1) + "</strong></div></html>";
			}
			else {
				newUrl = "<html><strong>" + url + "</strong></html>";
			}
			lbl.setText(newUrl);
		}
	}

}
